home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / util / misc / MultiRen.lha / MultiRen / Developers / Test-Plugin.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-03  |  4.5 KB  |  155 lines

  1. /* Test-plugin v1.0 by Deniil 715! rev.#1 for MultiRen
  2.    Made 2000-04-16
  3.  
  4.    E-mail to me, Daniel Westerberg: deniil@algonet.se
  5. */
  6.  
  7. #include<proto/exec.h>
  8. #include<proto/dos.h>
  9. #include<proto/intuition.h>
  10. #include<exec/tasks.h>
  11. #include<intuition/intuition.h>
  12. #include<stdlib.h>
  13. #include<stdio.h>
  14.  
  15. #define _VER "$VER: Test-plugin v1.0 by Deniil 715! rev.#1 (2000-04-16)"
  16. #define NUMSTRINGS_FOR_THIS_PLUGIN 2
  17. #define FILE_NAME_LENGTH 512
  18. #define COM_ASK 1
  19. #define COM_EXTRACT 2
  20. #define COM_CONFIGURE 3
  21. #define COM_ABOUT 4
  22. #define COM_QUIT 5
  23. #define ERR_OK 0
  24. #define ERR_NOMEM 1
  25. #define ERR_NOFILE 2
  26. #define ERR_NOSIG 3
  27. #define ERR_NOTIMPL 4
  28. #define ERR_UNKNOWN 5
  29. #define ERR_OTHER 6
  30. #define ERR_WRONGFORMAT 7
  31. #define ERR_FATAL 20
  32.  
  33. struct multiren_plugin {
  34.   long id;
  35.   Task *task;
  36.   long sig;
  37.   short ret;
  38.   char command;
  39.   char numstrings;       /* You will */
  40.   char *stringlist[256]; /* only use */
  41.   char *name;            /* these 3 elements */
  42. };
  43.  
  44. short ask(void);
  45. short extract(void);
  46. short configure(void);
  47. short about(void);
  48. short cleanup(void);
  49. short req(char*,char*);
  50.  
  51. struct multiren_plugin *mrp;
  52. char ascii[5], hex[9];
  53.  
  54. int main(int argc,char *argv[]) {
  55.   char sigbit;
  56.   long sig, msig;
  57.   Task *mtask;
  58.   if(DOSBase=(struct DosLibrary*)OpenLibrary("dos.library",0)) {
  59.     if(IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",0)) {
  60.       if(argc==2) {
  61.         if(mrp=(struct multiren_plugin*)atol(argv[1])) {
  62.           if(mrp->id==*(long*)"MRPO") {
  63.             if((sigbit=AllocSignal(-1))>=0) {
  64.               sig=1<<sigbit;
  65.               while(1) {
  66.                 switch(mrp->command) {
  67.                 case COM_ASK:
  68.                   mtask=mrp->task;
  69.                   msig=mrp->sig;
  70.                   mrp->ret=ask();
  71.                   SetProgramName(mrp->name);
  72.                   mrp->task=FindTask(0L);
  73.                   mrp->sig=sig;
  74.                   break;
  75.                 case COM_EXTRACT:   mrp->ret=extract(); break;
  76.                 case COM_CONFIGURE: mrp->ret=configure(); break;
  77.                 case COM_ABOUT:     mrp->ret=about(); break;
  78.                 case COM_QUIT:
  79.                   mrp->ret=cleanup();
  80.                   FreeSignal(sigbit);
  81.                   CloseLibrary((struct Library*)DOSBase);
  82.                   Signal(mtask,msig);
  83.                   return 0;
  84.                 default:
  85.                   mrp->ret=ERR_UNKNOWN;
  86.                 }
  87.                 Signal(mtask,msig);
  88.                 Wait(sig);
  89.               }
  90.             }
  91.             else {
  92.               mrp->ret=ERR_NOSIG;
  93.               Signal(mrp->task,mrp->sig);
  94.               return 0;
  95.             }
  96.           }
  97.         }
  98.       }
  99.       CloseLibrary((struct Library*)IntuitionBase);
  100.     }
  101.     CloseLibrary((struct Library*)DOSBase);
  102.   }
  103.   printf("This is a plugin for MultiRen!\n"
  104.          "It is not supposed to be executed manually!\n"
  105.          "Use it through the Renplacer tool in MultiRen instead!\n");
  106.   return ERR_FATAL;
  107. }
  108.  
  109. short ask() {
  110.   mrp->numstrings=NUMSTRINGS_FOR_THIS_PLUGIN;  /* I will return 2 strings */
  111.   mrp->stringlist[0]="First 4 bytes as hex";   /* Setting information-strings */
  112.   mrp->stringlist[1]="First 4 bytes as ASCII";
  113.   mrp->name="Test Plugin";                     /* This plugins name */
  114.   return ERR_OK; /* This plugin can't fail in initiation */
  115. }
  116.  
  117. short extract() { /* Do my stuff.. */
  118.   BPTR fh;
  119.   long len;
  120.   if(fh=Open(mrp->name,MODE_OLDFILE)) { /* Open the file that later is going to be renamed. */
  121.     len=Read(fh,ascii,4L);
  122.     Close(fh);
  123.     hex[8]='\0';
  124.     ascii[4]='\0';
  125.     if(len!=4L) return ERR_OTHER;
  126.     sprintf(hex,"%08lX",*(long*)ascii);
  127.     mrp->stringlist[0]=hex;   /* Set the pointer so that MultiRen.. */
  128.     mrp->stringlist[1]=ascii; /* ..can get my strings. */
  129.     return ERR_OK; /* My stuff went ok */
  130.   }
  131.   return ERR_NOFILE; /* The file didn't open */
  132. }
  133.  
  134. short configure() { return ERR_NOTIMPL; } /* There is no config for this plugin */
  135.  
  136. short about() {
  137.   if(req("Test Plugin v1.0 by Deniil 715! for MultiRen\n\n"
  138.          "It was made 2000-04-16 in Amiga-E\n\n"
  139.          "E-mail: deniil@algonet.se","More|OK"))
  140.     req("This plugin will return the first 4 bytes\n"
  141.         "of the file to rename in two ways. The first\n"
  142.         "string will be the 4 bytes in hexadecimal,\n"
  143.         "the other one just as a plain string.","OK");
  144.   return ERR_OK;
  145. }
  146.  
  147. short cleanup() { return ERR_OK; }
  148.  
  149. short req(char *body,char *gads) {
  150.   struct EasyStruct tags;
  151.   tags.es_Title="Test Plugin";
  152.   tags.es_TextFormat=body;
  153.   tags.es_GadgetFormat=gads;
  154.   return EasyRequestArgs(NULL,&tags,NULL,NULL);
  155. }